Skip to content

matiasarenhard/rails-cve-2017-17917

Repository files navigation

rails-cve-2017-17917

The project demonstrates the replication of a SQL injection vulnerability in the id parameter, and subsequently provides insights into mitigating and resolving this security issue. https://www.cvedetails.com/cve/CVE-2017-17917/?q=CVE-2017-17917

Stack:

  Ruby: 3.2.2
  Rails: 7.0.8
  Docker 24.0.5
  Docker-Compose 1.29.2
  PostgreSQL

image

We selected this CVE to highlight the persisting occurrence of this issue in the latest versions of Rails, reaffirming its relevance of the development best practices.

Schema from the environment to replicate the vulnerability

Diagrama sem nome drawio(1)

Instructions to replicate this vulnerability.

Requirements:

  docker
  docker-compose

Steps to build a project:

  sudo docker-compose build

image

  sudo docker-compose run web bundle install

image

  sudo docker-compose run web rails db:create db:migrate db:seed

image

  sudo docker-compose up

image

Go to http://localhost:3000/

image

image

SQL Injection param 1 OR id > 1

image

Assessing the risks of the vulnerability in a production environment.

With this SQL injection, an attacker can retrieve user data they wouldn't normally have access to view.
degree difficulty to execution: easy

Conclusion

The issue lies in the controller method, specifically when invoking a where clause as follows:
@clients = Client.where("id = #{params[:id_search]}")
Link to Code

The problem is resolved by using the following approach:
@clients = Client.where(id: "#{params[:id_search]}")
Link to Code

Tests

  sudo docker-compose run web rspec

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published